<?php
 
defined('DSVH') or die('Restricted access');
 
//add chuc danh
function insertwebsite($local){
    mysql_query("insert website set ten_website = '".$local['ten_website']."',
    avatar = '".$local['avatar']."',
    link = '".$local['link']."',
    loai_website_id = '".$local['loai_website_id']."',
    mo_ta_chung = '".$local['mo_ta_chung']."',
    keyword = '".$local['keyword']."',
    add_date = NOW(),
    mo_ta_chi_tiet = '".$local['mo_ta_chi_tiet']."'",
    dbconnect());
}

function insertloaiwebsite($local){
    mysql_query("insert loai_website set ten_loai_website = '".$local['ten_loai_website']."',
    user_id = '".$local['avatar']."',
    sap_xep = '".$local['sap_xep']."',
    add_date = NOW()",
    dbconnect());
}

function editloaiwebsite($id, $local)
{
    mysql_query("update loai_website set ten_loai_website ='".$local['ten_loai_website']."',
    sap_xep = '".$local['sap_xep']."',
    add_date = NOW() 
    where loai_website_id = '".(int)$id."'", dbconnect());
}
//list chuc danh
function getListwebsite($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM website
        left join loai_website  ON website.loai_website_id = loai_website.loai_website_id
        order by website_id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    

function getListloaiwebsite($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM loai_website
        order by loai_website_id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    
//ham lay du lieu phong ban theo id
function getwebsite($id)
    {
    $pro = mysql_query("select * from website where website_id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
function getloaiwebsite($id)
    {
    $pro = mysql_query("select * from loai_website where loai_website_id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
//cap nhat trong muc sua
function editwebsite($id, $local)
{
    mysql_query("update website set ten_website ='".$local['ten_website']."',
    avatar = '".$local['avatar']."',
    link = '".$local['link']."',
    loai_website_id = '".$local['loai_website_id']."',
    mo_ta_chung = '".$local['mo_ta_chung']."',
    keyword = '".$local['keyword']."',
    add_date = NOW(),
    mo_ta_chi_tiet = '".$local['mo_ta_chi_tiet']."' 
    where website_id = '".(int)$id."'", dbconnect());
}

// xoa thu muc
function delwebsite($id){
    mysql_query("delete from website where website_id ='".(int)$id."'", dbconnect());
}

function total(){
   $result = mysql_query("select * from website",dbconnect());
    return mysql_num_rows($result);
}

function totalloaiwebsite(){
   $result = mysql_query("select * from loai_website",dbconnect());
    return mysql_num_rows($result);
}

 function checkcanbo($param){
    $sql = "SELECT * FROM can_bo where website_id = '".escape($param)."'";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
}

function check_hoso_pvt($param){
    $sql = "SELECT * FROM ho_so_phi_vat_the where website_id = '".escape($param)."'";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
}



?>